/*
 * @Author: your name
 * @Date: 2020-11-14 08:37:28
 * @LastEditTime: 2021-05-04 14:58:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \HDZP\HDY-Perfect\src\utils\index.js
 */

export const getParamsString = (name) => {
  // 获取URL中的code
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) {
    // console.log('code===', unescape(r[2]))
    return unescape(r[2]);
  }
  return null;
}

export const getQueryString = (url, name) => {
  // 获取URL中的code
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  var r = url.substr(1).match(reg);
  console.log(r)
  if (r != null) {
    // console.log('code===', unescape(r[2]))
    return unescape(r[2]);
  }
  return null;
}

export function getTime(nS) {
  var date = new Date(parseInt(nS) * 1000);
  var year = date.getFullYear();
  var mon = date.getMonth() + 1;
  var day = date.getDate();
  var hours = date.getHours();
  var minu = date.getMinutes();
  var sec = date.getSeconds();

  return year + '/' + mon + '/' + day + ' ' + hours + ':' + minu + ':' + sec;
}

export function getINeedParams(sourceData, ...params) {
  console.log(sourceData, params, arguments)
}



export function mixRoute(history, path, type = 'push') {
  const isApplet = (window.__wxjs_environment === 'miniprogram')
  console.log(type, path, 'isApplet:', isApplet)
  if (isApplet) { //applet route
    switch (type) {
      case 'push':
        window.navigateToWebWiew(path)
        break;
      case 'goBack':
        window.navigateGoBack()
      default:
        break;
    }
  } else { // h5 route
    switch (type) {
      case 'push':
        history.push(path)
        break;
      case 'goBack':
        history.goBack(path)
        break;
      default:
        break;
    }
  }
}







